package top.fengyulou.code.service;

import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import top.fengyulou.common.Jr;
import top.fengyulou.common.UserUtils;
import top.fengyulou.code.dao.UserDao;
import top.fengyulou.code.entity.UserForm;

import javax.annotation.Resource;

/**
 * 接口
 */
@Service
public class UserService {

    @Resource
    private UserDao userDao;

    /**
     * 用户登录
     *
     * @param form
     * @return
     */
    public Jr login(UserForm form) {
        UserForm byLoginName = userDao.getByLoginName(form);
        if (ObjectUtils.isNotEmpty(byLoginName)) {
            String password = byLoginName.getPassword();
            String pwd = UserUtils.getPwd(form.getPassword(), byLoginName.getRandomStr());
            if (password.equals(pwd)) {
                return Jr.yes(byLoginName);
            }
        }
        return Jr.no();
    }
}
